﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>培训类型编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../static/css/font.css">
    <link rel="stylesheet" href="../../../static/css/weadmin.css">
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
    <div class="weadmin-body">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="FTName" class="layui-form-label">
                    <span class="we-red">*</span>类型名称
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="FTName" name="FTName" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <label for="FTDescribe" class="layui-form-label">
                    <span class="we-red"></span>类型描述
                </label>
                <div class="layui-input-inline">
                    <input type="text" id="FTDescribe" name="FTDescribe" lay-verify="nikename" autocomplete="off"  class="layui-input">
                </div>
                 
                    <input type="text" id="FTID" name="FTID" class="layui-input" hidden="hidden">
 
            </div>
 
            <div class="layui-form-item">
                <button class="layui-btn" lay-filter="add" lay-submit="">确定</button>
            </div>
        </form>
    </div>
    <script src="../../../lib/layui/layui.js" charset="utf-8"></script>
    <script src="../../../static/js/common.js" charset="utf-8"></script>

    <script>
        layui.use(['form', 'jquery', 'layer', 'laydate'], function () {
            var form = layui.form,
                $ = layui.jquery,
                layer = layui.layer,
                laydate = layui.laydate;
            $("#FTID").hide();
            $(function () { 
                //加载部门信息，角色信息，机务段信息结束
                //加载人员信息
                var editdata = {};
                var empajax = $.ajax({
                    url: ApiUrl + "TrainFileType",
                    type: 'get',
                    dataType: 'json',
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: { id: getUrlParam("FTID") },
                    success: function (data) {
                        editdata = JSON.parse(data);
                    }
                });
                //加载人员信息结束
                //相关ajax加载完成后，绑定数据
                $.when(empajax)
                    .done(function () {
                        console.log(editdata)
                        for (var key in editdata) {
                                $("#" + key).val($.trim(editdata[key]));
                        }
                        form.render();
                    })
                    .fail(function () {
                        console.log("test4")
                    });
            })
            form.on('submit(add)', function (formdata) {
                $.ajax({
                    url: ApiUrl + "TrainFileType/Edit",
                    type: 'post',
                    dataType: 'json',
                    cache: false,
                    headers: {
                        "userid": JSON.parse(window.localStorage.authInfo).UserId,
                        "signtoken": JSON.parse(window.localStorage.authInfo).SignToken,
                    },
                    data: formdata.field,
                    success: function (data) {
                        console.log(data)
                        if (data.StatusCode == 200) {
                            layer.alert("编辑成功", { icon: 6 }, function (index) {
                                parent.layer.closeAll();
                            })
                        }
                        else if (data.StatusCode == 403) {
                            top.layer.alert(data.Info + ",请重新登录！", { closeBtn: 0 }, function () {
                                top.location.href = "http://" + top.location.host + "/login.html";
                            })
                        }
                        else {
                            layer.msg(data.Info);
                        }
                    }
                });
                return false;
            });
        });
    </script>
</body>
</html>